<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Class与Style绑定</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <!-- 绑定class -->
    <div class="static" v-bind:class="{active:isActive,'text-danger':hasError}"></div>
    <!-- 绑定class对象 -->
    <div id="vue2" class="static" v-bind:class="classOject"></div>
    <!-- 计算属性绑定 -->
    <div id="vue3" class="static" v-bind:class="classOject"></div>
    <!-- 数组语法 -->
    <div id="vue4" class="static" v-bind:class="[activeClass,errorClass]"></div>
    <!-- 绑定内联样式 -->
    <div id="vue5" v-bind:style="styleObject">绑定内联样式</div>
    <div v-bind:style="[baseStyles, overridingStyles]"></div><!--数组语法-->
    <div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"></div><!--多重值-->
    <script>
        let vue5 = new Vue({
            el:"#vue5",
            data:{
                styleObject:{
                    color:'red',
                    fontSize:'13px'
                }
            }
        })
        let vue1 = new Vue({
            el: 'div',
            // 单个绑定
            data: {
                isActive: true,
                hasError: true,
                
            }
        })

        let vue2 = new Vue({
            el: '#vue2',
            data: {
                // 对象绑定
                classOject: {
                    active: true,
                    'text-danger': false
                }
            }
        })

        // 计算属性
        let vue3 = new Vue({
            el: '#vue3',
            data: {
                isActive: true,
                hasError: null
            },
            computed: {
                classOject: function () {
                    return {
                        active: this.isActive && !this.hasError ,
                        'text-danger': this.hasError===null
                    }
                }
            }
        })
        let vue4 = new Vue({
            el:'#vue4',
            data:{
                activeClass:'active',
                errorClass:'text-danger'
            }
        })

    </script>
</body>

</html>